package com.person.leetcode.editor.cn;

/**
 * 467.环绕字符串中唯一的子字符串
 * 2022-05-25 09:15:21
 **/
public class Sequence_0467_UniqueSubstringsInWraparoundString {
    public static void main(String[] args) {
        Solution solution = new Sequence_0467_UniqueSubstringsInWraparoundString().new Solution();
        System.out.println((char) ('b' + 1));
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        //对于每个长子串都有n(n+1)/2

        public int findSubstringInWraproundString(String p) {
            //他妈的,看不懂答案
            //没考虑重复的情况
            int i = 0, j = 1, ans = 0;
            while (j < p.length()) {
                char suf = p.charAt(j);
                char pref = p.charAt(j - 1);
                if (suf - pref == 1 || (suf == 'a' && pref == 'z')) {
                    j++;
                } else {
                    ans += (j - i) * (j - i + 1) / 2;
                    i = j;
                    j = i + 1;
                }
            }
            ans += (j - i) * (j - i + 1) / 2;
            return ans;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
